home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / dev / c / libmpeg_src.lha / extras / easympeg.c next >
Encoding:
C/C++ Source or Header  |  1995-07-18  |  2.1 KB  |  93 lines

  1. /*
  2.  * The World's Easiest MPEG Player -- a demonstration of the MPEG Library,
  3.  * written for Silicon Graphics machines.  Demonstrates basic use of 
  4.  * the MPEG Library, in either true-colour or colour-mapped dithering
  5.  * modes.  Yes, it is possible to write an MPEG player in less than
  6.  * 100 lines of code...
  7.  *
  8.  * Masochists may port to X (or whatever) if desired.
  9.  *
  10.  * By Greg Ward, 94/8/15
  11.  *   modified for colour-mapped modes, March '95.
  12.  */
  13.  
  14. #include <stdlib.h>
  15. #include <errno.h>
  16. #include <gl.h>
  17. #define BOOLEAN_TYPE_EXISTS
  18. #include "mpeg.h"
  19.  
  20.  
  21. int main (int argc, char *argv[])
  22. {
  23.    FILE       *mpeg;
  24.    ImageDesc   img;
  25.    char       *pixels;
  26.    Boolean     moreframes = TRUE;
  27.    Boolean     full_color = TRUE;
  28.    Boolean     loop = TRUE;
  29.    
  30.    if (argc != 2) 
  31.    {
  32.       fprintf (stderr, "Usage: %s mpegfile\n", argv[0]);
  33.       exit (1);
  34.    }
  35.  
  36.    mpeg = fopen (argv[1], "r");
  37.    if (!mpeg)
  38.    {
  39.       perror (argv[1]);
  40.       exit (1);
  41.    }
  42.       
  43.    SetMPEGOption (MPEG_DITHER, 
  44.           (full_color) ? (int) FULL_COLOR_DITHER : 
  45.                          (int) ORDERED_DITHER);
  46.    if (!OpenMPEG (mpeg, &img))
  47.    {
  48.       fprintf (stderr, "OpenMPEG on %s failed\n", argv[1]);
  49.       exit (1);
  50.    }
  51.  
  52.    pixels = (char *) malloc (img.Size * sizeof(char));
  53.    printf ("Movie is %d x %d pixels\n", img.Width, img.Height);
  54.    printf ("Required picture rate = %d, required bit rate = %d\n",
  55.        img.PictureRate, img.BitRate);
  56.  
  57.    foreground ();
  58.    prefsize (img.Width, img.Height);
  59.    winopen ("Easy MPEG");
  60.    if (full_color) RGBmode ();
  61.    pixmode (PM_SIZE, img.PixelSize);
  62.    pixmode (PM_TTOB, 1);
  63.    gconfig ();
  64.    clear ();
  65.  
  66.    if (!full_color)
  67.    {
  68.       int  i;
  69.  
  70.       for (i = 0; i < img.ColormapSize; i++)
  71.       {
  72.      mapcolor (i, 
  73.            img.Colormap[i].red, 
  74.            img.Colormap[i].green, 
  75.            img.Colormap[i].blue);
  76.       }
  77.       gflush ();
  78.    }
  79.    
  80.    while (loop)            /* play the whole movie forever */
  81.    {
  82.       while (moreframes)    /* play frames until the movie ends */
  83.       {
  84.      moreframes = GetMPEGFrame (pixels);
  85.      lrectwrite (0, 0, img.Width-1, img.Height-1,
  86.              (unsigned long *) pixels);
  87.       }
  88.  
  89.       RewindMPEG (mpeg, &img);
  90.       moreframes = TRUE;
  91.    }
  92. }
  93.